<template>
  <el-config-provider :size="globalComSize" :locale="zhCn">
    <router-view></router-view>
  </el-config-provider>
</template>

<script lang="ts" setup>
import { computed, onMounted } from "vue";
import { useSettingStore } from "@/store/modules/setting"
// 配置element中文
import zhCn from 'element-plus/es/locale/lang/zh-cn'
import { Logger } from "./engine/util/Logger";
import { EventConfig } from "./engine/event/EventConfig";
import { EventManager } from "./engine/event/EventManager";
import { UIHelper } from "./utils/UIHelper";
import { getTimeStateStr } from '@/utils/index'
import { ElNotification } from "element-plus";
import { UserModel } from "./store/model/UserModel";
import { useRouter } from 'vue-router'
const router = useRouter()

const SettingStore = useSettingStore()
// 配置全局组件大小
const globalComSize = computed((): string => SettingStore.themeConfig.globalComSize)

onMounted(() => {
  Logger.log("App.vue onMounted")
  EventManager.instance.clearAll();
  EventManager.instance.on(EventConfig.Event_Config.Logout, () => {

    UserModel.instance.logout();
    router.push({
      path: '/login',
    })

  }, this);

  EventManager.instance.on(
    EventConfig.Event_Config.Msg,
    (msg: string, msgType: string = UIHelper.Msg_Type.success) => {
      // Logger.log("EventManager ===msg=", msg, msgType);
      if (msgType == UIHelper.Msg_Type.success) {
        ElNotification({
          title: getTimeStateStr(),
          message: msg,
          type: "success",
          duration: 3000
        });
      }
      else if (msgType == UIHelper.Msg_Type.warning) {
        ElNotification({
          title: getTimeStateStr(),
          message: msg,
          type: "warning",
          duration: 3000
        });
      }
      else if (msgType == UIHelper.Msg_Type.normal) {
        ElNotification({
          title: getTimeStateStr(),
          message: msg,
          type: "info",
          duration: 3000
        });
      }
      else if (msgType == UIHelper.Msg_Type.error) {
        ElNotification({
          title: getTimeStateStr(),
          message: msg,
          type: "error",
          duration: 3000
        });
      }
    },
    this
  );

})



</script>

<style lang="scss">
#app {
  position: relative;
  width: 100%;
  height: 100%;
  font-family: Avenir, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  color: #2c3e50;
}

.el-pager li:focus {
  border: none;
}

.el-dropdown:focus {
  border: none;
}

.svg-icon:focus {
  border: none;
}
</style>
